<html>
<head><meta charset="utf-8"><title>AllocRef::grow and ReallocPlacement · t-libs/wg-allocators · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/index.html">t-libs/wg-allocators</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/AllocRef.3A.3Agrow.20and.20ReallocPlacement.html">AllocRef::grow and ReallocPlacement</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212451662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/AllocRef%3A%3Agrow%20and%20ReallocPlacement/near/212451662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Chartier <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/AllocRef.3A.3Agrow.20and.20ReallocPlacement.html#212451662">(Oct 06 2020 at 16:21)</a>:</h4>
<p>Hi, it looks like in nightly AllocRef::grow no longer takes a ReallocPlacement argument, is there a way to replicate this functionality?  For my use case,  it's ok for me to copy and extend my data, but I can't immediately move it (I'm creating a multi-writer append-only data structure that may have outstanding references).  Given the new interface, my assumption was that AllocRef::grow would error if it couldn't be done in place and then I could call AllocRef::alloc but that doesn't appear to be the case. As of now, it looks like I will always have to call AllocRef::alloc and can never extend my existing allocations.</p>



<a name="212495194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/AllocRef%3A%3Agrow%20and%20ReallocPlacement/near/212495194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/AllocRef.3A.3Agrow.20and.20ReallocPlacement.html#212495194">(Oct 06 2020 at 22:43)</a>:</h4>
<p>No allocators currently support in-place reallocation anyways, that's why it was removed.</p>



<a name="212495212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/AllocRef%3A%3Agrow%20and%20ReallocPlacement/near/212495212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/AllocRef.3A.3Agrow.20and.20ReallocPlacement.html#212495212">(Oct 06 2020 at 22:43)</a>:</h4>
<p>You'll just have to never reallocate, that's what C++ does for types with move constructors.</p>



<a name="212560281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/AllocRef%3A%3Agrow%20and%20ReallocPlacement/near/212560281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Chartier <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/AllocRef.3A.3Agrow.20and.20ReallocPlacement.html#212560281">(Oct 07 2020 at 13:46)</a>:</h4>
<p>Gotcha. That makes total sense. No reallocate it is.</p>



<a name="214509918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/AllocRef%3A%3Agrow%20and%20ReallocPlacement/near/214509918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/AllocRef.3A.3Agrow.20and.20ReallocPlacement.html#214509918">(Oct 25 2020 at 20:19)</a>:</h4>
<blockquote>
<p>No allocators currently support in-place reallocation anyways, that's why it was removed.</p>
</blockquote>
<p>mimalloc has a in-place-only reallocation API, FWIW: (mi_expand returns null if it cant happen in-place) <a href="https://microsoft.github.io/mimalloc/group__malloc.html#gaaee66a1d483c3e28f585525fb96707e4">https://microsoft.github.io/mimalloc/group__malloc.html#gaaee66a1d483c3e28f585525fb96707e4</a></p>



<a name="214510657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/AllocRef%3A%3Agrow%20and%20ReallocPlacement/near/214510657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/AllocRef.3A.3Agrow.20and.20ReallocPlacement.html#214510657">(Oct 25 2020 at 20:34)</a>:</h4>
<p>What is the actual use case for that though?</p>



<a name="214511207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/AllocRef%3A%3Agrow%20and%20ReallocPlacement/near/214511207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/AllocRef.3A.3Agrow.20and.20ReallocPlacement.html#214511207">(Oct 25 2020 at 20:45)</a>:</h4>
<p>Oh, I think it makes a lot more sense for C++ where move requires extra work. I don't think there's a lot of use case for Rust.</p>



<a name="214526807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/AllocRef%3A%3Agrow%20and%20ReallocPlacement/near/214526807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/AllocRef.3A.3Agrow.20and.20ReallocPlacement.html#214526807">(Oct 26 2020 at 02:34)</a>:</h4>
<p>Mimalloc's impl also just checks if the requested size is the same as the "true" size, and if so returns it. AllocRef handles the "true" size of the allocation more explicitly, so there's really no use for this in it.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>